/*
 * @Author: wurangkun
 * @Date: 2024-07-12 21:53:25
 * @LastEditTime: 2024-07-24 17:45:28
 * @LastEditors: wurangkun
 * @FilePath: \my-app\app\pages\login\index.tsx
 * @Description: 
 */
import { ScreenBar } from '@/components/ScreenBar'
import { router, Stack, useNavigation } from 'expo-router'
import { StackActions } from "@react-navigation/native";
import React from 'react'
import { View, ScrollView, DeviceEventEmitter } from 'react-native'
import { SafeAreaView } from 'react-native-safe-area-context'

import { Button } from '@ant-design/react-native'
import { userUserStore } from '@/app/store/user'
import { replace, toHome } from '@/hooks/routerHooks';
import Page from '@/components/page';

export default function Login() {
  const { userInfo, setUserInfo } = userUserStore()
  const navigation = useNavigation();

  const handlePopToTop = () => {
    console.log('popToTop', StackActions.popToTop())
    // navigation.navigate('index')
    // navigation.dispatch(StackActions.popToTop());
    // router.replace('/')
    toHome()
    DeviceEventEmitter.emit('refresh_tab')
    // navigation.reset({
    //   index: 0,
    //   routes: [{ name: 'pages/haha/index' }],
    // });
  };
  const toHaha = () => {
    setUserInfo({
      name: 'haha',
      id: 0,
      email: '',
      password: '',
      role: ''
    })
    if (router.canGoBack())
      handlePopToTop()
    else {
      replace('/')
    }
  }
  return (
    < >
      <Page title='登录' animation='none' animationDuration={0}>
        <View style={{ flex: 1, backgroundColor: "#f6f7f9" }}>
          <ScrollView scrollEnabled={true} style={{ width: '100%' }}>
            <SafeAreaView edges={['bottom']} style={{ flex: 1, width: '100%', }}>
              <Button onPress={toHaha}>to home</Button>
            </SafeAreaView>
          </ScrollView>
        </View >
      </Page>
    </>
  )
}
